package com.clubs.coding.Service.Impl;

import com.clubs.coding.Service.AthRecordService;
import com.clubs.coding.exception.ImoocMallException;
import com.clubs.coding.exception.ImoocMallExceptionEnum;
import com.clubs.coding.model.dao.AthRecordMapper;
import com.clubs.coding.model.dao.UserMapper;
import com.clubs.coding.model.pojo.AthRecord;
import com.clubs.coding.model.pojo.User;
import com.clubs.coding.model.request.AthAdminRecordReq;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class AthRecordServiceImpl implements AthRecordService {
@Autowired
    AthRecordMapper athRecordMapper;
@Autowired
    UserMapper userMapper;
@Override
public Integer rest(String openid){
    User byOpenid = userMapper.findByOpenid(openid);
    if (byOpenid ==null) {
        throw new ImoocMallException(ImoocMallExceptionEnum.OPENID_NO);
    }
    Integer id = byOpenid.getId();
    AthRecord athRecord = athRecordMapper.selectByUserId(id);
    Integer restRecord = athRecord.getRestRecord();
    return restRecord;

}
    /**
     * 课时管理
     * **/
    @Override
public void record(AthAdminRecordReq athAdminRecordReq){
    AthRecord athRecord = new AthRecord();
    BeanUtils.copyProperties(athAdminRecordReq,athRecord);
    int i = athRecordMapper.updateByUserid(athRecord);
}

}
